<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
  defined('_JEXEC') or die('Retricted Access');
?>
<script type="text/javascript">
	function gotoaction(){
		if($('action0').checked){
			$('task').value = 'duplicate';
		}
		else if($('action1').checked){
			$('task').value = 'import';
		}
		document.adminForm.submit();
	}

</script>
<form name="adminForm" action="index.php" method="post">
<table width="100%">		
	<tr>
		<td align="left" width="100%">
			<?php echo JText::_( 'Filter name' ); ?>:
			<input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
			<input type="button" onclick="this.form.submit();" value="<?php echo JText::_( 'Go' ); ?>">
			<input type="button" onclick="document.getElementById('search').value=''; document.getElementById('filter_lang').value='0'; document.getElementById('filter_state').value='';this.form.submit();" value="<?php echo JText::_( 'Filter Reset' ); ?>">
		</td>
		<td  align="right" nowrap="nowrap">
			<?php echo $this->languages; ?>
			<?php echo $this->lists['state']; ?>
		</td>
	</tr>
</table>

<table width="100%" class="adminlist">	
        	<thead>
            	<tr>
            		
            		<th width="30%">
            			<?php echo JHTML::_('grid.sort',   JText::_('Email Group'), 'group',@$this->order_dir, @$this->order); ?>
            		</th>
            		<th >
            			<table width="100%">
            				<tr>
            					<td style="background-color:#F0F0F0;border: 0px;" width="5%">
            						<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo $this->counts; ?>);" />
            					</td>
            					
            					<td  style="background-color:#F0F0F0;border: 0px;">
            						<?php echo JHTML::_('grid.sort',   JText::_('Email title'), 'title',@$this->order_dir, @$this->order); ?>
            					</td>
            					<td  style="background-color:#F0F0F0;border: 0px;" width="15%">
            						<?php echo JText::_('Status/Action') ?>
            					</td>
            					<td  style="background-color:#F0F0F0;border: 0px;" width="10%">
            						<?php echo JHTML::_('grid.sort',   JText::_('Is System'), 'system',@$this->order_dir, @$this->order); ?>
            					</td>
            					<td width="10%" style="background-color:#F0F0F0;border: 0px;" align="center">
            						<?php echo JHTML::_('grid.sort',   JText::_('Published'), 'is_published',@$this->order_dir, @$this->order); ?>
            					</td>
            				</tr>
            			</table>
            		</th>            		          		            		
  
            	</tr>
			</thead>
			<tbody>
        	<?php
			
        	$items = $this->items;
        	$en_items = $this->en_items;
        	$k = 0;
        	for($i = 0; $i < count($this->arr_group); $i++){
        		$group = $this->arr_group[$i];
				
        		?>
        		<tr class="row<?php echo $i%2; ?>">
					<td style="font-weight:bold;">					
						<?php echo $group; ?>
					</td>
            		<td>
            			<table class="adminlist">
							<?php if(!isset($items[$i]) && isset($en_items[$i])){?>
								<?php foreach ($en_items[$i] as $item){?>
									<tr>
			            				<td width="5%">
			            					<input type='checkbox' name=cid[] disabled=true/>
			            				</td> 
			            				<td>
		            						<?php echo $item['title']; ?> 
		            						<a href="<?php echo JRoute::_( 'index.php?option='. $this->lists['option'] .'&view=jaemail&task=duplicate&filter_lang='.$this->filter_lang.'&cid='.$item['id'] ); ?>" onclick="return confirm('<?php echo JText::_('Are you sure you want to copy the template from this default template?')?>')" title="<?php echo JText::_('Email template does not exist, click here to copy it from the default file'); ?>"><img src="<?php echo JURI::base()?>components/com_jajobboard/css/copy-32x32.png" alt="Copy" /></a>
		            					</td>
				            			<td align="center" colspan="3">				            			
				            			</td>
				            		</tr>
				            	<?php }?>
							<?php }
							
							elseif(isset($items[$i]) && isset($en_items[$i])){?>
							
								<?php $temp = $this->getModel('jaemail');$diff = $temp->diff_multi_array($en_items[$i], $items[$i], 'name');?>
								
								<?php if($diff){?> 
									<?php foreach ($diff as $item){?>
										<tr>
				            				<td width="5%">
				            					<input type='checkbox' name=cid[] disabled=true/>
				            				</td> 
				            				<td>
			            						<?php echo $item['title']; ?>
			            						<a href="<?php echo JRoute::_( 'index.php?option='. $this->lists['option'] .'&view=jaemail&task=duplicate&filter_lang='.$this->filter_lang.'&cid='.$item['id'] ); ?>" onclick="return confirm('<?php echo JText::_('Are you sure you want to copy the template from this default template?')?>')" title="<?php echo JText::_('Email template does not exist, click here to copy it from the default file'); ?>"><img src="<?php echo JURI::base()?>components/com_jajobboard/css/copy-32x32.png" alt="Copy" /></a>
			            					</td>
					            			<td align="center" colspan="3">				            			
				            				</td>
					            		</tr>
					            	<?php }?>	
								<?php }?>
								
								<?php foreach ($items[$i] as $item){									
									$temp = new stdClass();
									$temp->id = $item['id'];
									$temp->published = $item['published'];
									$published 	= JHTML::_('grid.published', $temp, $k );
									$temp->checked_out = 0;
									$checked 	= JHTML::_('grid.checkedout',   $temp, $k );
									?>
									<tr>
			            				<td width="5%">
			            					<?php 
			            						if ($item['system']!=1)
			            							echo $checked; 
			            						else 					
			            							echo "<input type='checkbox' name=cid[] disabled=true/>"
			            					?> 
			            				</td> 
			            				<td>
		            						<a href="<?php echo JRoute::_( 'index.php?option='. $this->lists['option'] .'&view=jaemail&task=edit&cid[]='.$item['id'] ); ?>">
	            								<?php echo $item['title']; ?>
	            							</a>
		            					</td>
		            					<td width="15%" align="center" colspan="2">
				            				 
				            			</td>
				            			
				            			<td width="10%" align="center">
				            				<?php echo $published ?>
				            			</td>
				            		</tr>
				            		<?php $k++;?>
				            	<?php }?>	
							
							<?php }
							
							elseif(isset($items[$i])){?>
								
								<?php foreach ($items[$i] as $j=>$item){
									
									$temp = new stdClass();
									$temp->id = $item['id'];
									$temp->published = $item['published'];
									$published 	= JHTML::_('grid.published', $temp, $k );
									$temp->checked_out = 0;
									$checked 	= JHTML::_('grid.checkedout',   $temp, $k );
									?>
									<tr>
			            				<td width="5%">
			            					<?php echo $checked;?> 
			            				</td> 
			            				<td>
		            						<a href="<?php echo JRoute::_( 'index.php?option='. $this->lists['option'] .'&view=jaemail&task=edit&cid[]='.$item['id'] ); ?>">
	            								<?php echo $item['title']; ?>
	            							</a>
		            					</td>
		            					<td width="15%" align="center">
				            				<?php 
			            						if ($item['system']){
			            							if($item['modified']){
			            								$confirm = JText::_('Are you sure you want to restore this email template? If you choose Yes, the changes will be lost. Email Template will be restored to the original default.');
			            								?>
			            								<img src="components/com_jajobboard/images/modified.gif" title="<?php echo JText::_('Modified')?>" alt="<?php echo JText::_('Modified')?>"/>
			            							 	 [<a onclick="return confirm('<?php echo $confirm?>')" href="index.php?option=com_jajobboard&view=jaemail&task=restore&cid[]=<?php echo $item['id']?>" title="<?php echo JText::_('Restore to default')?>"><?php echo JText::_('Restore')?></a>]
			            							 <?php }else{?>
			            							 	<img src="components/com_jajobboard/images/notmodified.gif" title="<?php echo JText::_('Not Modified')?>" alt="<?php echo JText::_('Not Modified')?>"/>
			            							 <?php }?>
			            							 
			            						<?php } else{?>
													<img src="components/com_jajobboard/images/usercreated.gif" title="<?php echo JText::_('User Created')?>" alt="<?php echo JText::_('User Created')?>"/>
			            						 <?php }
			            							
			            					?> 
				            			</td>
				            			<td width="10%" align="center">
				            				<?php if($item['system']){?>
				            					<img border="0" alt="This is system." src="templates/khepri/images/menu/icon-16-default.png"/>
				            				<?php }?>
				            			</td>
				            			<td width="10%" align="center">
				            				<?php echo $published ?>
				            			</td>
				            		</tr>
				            		<?php $k++;?>
				            	<?php }?>	
							
							<?php }?>								            				
            					
            			</table>
            		</td>                		        		            		
            	</tr>
        	<?php }?>
	<tbody>
	<tfoot>
		<tr>
			<td colspan="6">	
				<img src="components/com_jajobboard/images/notmodified.gif" title="<?php echo JText::_('Default')?>" alt="<?php echo JText::_('Default')?>"/>: <?php echo JText::_('Not Modified')?>
				|						
				<img src="components/com_jajobboard/images/modified.gif" title="<?php echo JText::_('Modified')?>" alt="<?php echo JText::_('Modified')?>"/>: <?php echo JText::_('Modified')?>
				| 
				<img src="components/com_jajobboard/images/usercreated.gif" title="<?php echo JText::_('User Created')?>" alt="<?php echo JText::_('User Created')?>"/>: <?php echo JText::_('User Created')?>
			</td>
		</tr>
	</tfoot>
</table>
	
	
	<input type="hidden" name="option" value="<?php echo $this->lists['option']; ?>" />
	<input type="hidden" name="view" value="jaemail" />
	<input type="hidden" name="task" id="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
